resize-world -100 100 -100 100
ask patches [ set pcolor [235 235 235]]
let x-axes patches with [
let y-axes patches with [
let beginpt one-of turtles with [ xcor = min-pxcor and ycor = 0 ]
let endpt one-of turtles with [ xcor = max-pxcor and ycor = 0 ]
let origin one-of turtles with [ xcor = 0 and ycor = 0 ]
ask beginpt [ create-link-with origin ]
ask origin [ create-link-with endpt ]
let beginpt one-of turtles with [ ycor = min-pycor and xcor = 0 ]
let endpt one-of turtles with [ ycor = max-pycor and xcor = 0 ]
let origin one-of turtles with [ xcor = 0 and ycor = 0 ]
ask beginpt [ create-link-with origin ]
ask origin [ create-link-with endpt ]
ask turtles with [xcor = 0 and ycor = 0] [
if xcord = max-pxcor [ stop ]
let y calculate-function xcord
ask patches with [ pxcor = xcord and pycor = round y] [sprout-points 1 [ setup-appearance ]]
if xcord = max-pxcor - 1[ stop ]
let y calculate-function xcord
if y < max-pycor and y > min-pycor [
let prev one-of turtles with [ xcor = xcord and ycor = round y]
let nexty calculate-function (xcord + 1)
if nexty < max-pycor and y > min-pycor [
let next one-of turtles with [ xcor = (xcord + 1) and ycor = round nexty]
if y > min-pycor and y < max-pxcor and nexty > min-pycor and nexty < max-pycor [
ask prev [create-link-with next ask my-links [set color black]]
to-report calculate-function [input]
let value constant + x1-coefficient * (input) / max-pxcor + x2-coefficient * ((input) / max-pxcor)^(2) + x3-coefficient * ((input) / max-pxcor)^(3) + x4-coefficient * ((input) / max-pxcor)^(4) + x5-coefficient * ((input) / max-pxcor)^(5) + x6-coefficient * ((input) / max-pxcor)^(6) + x7-coefficient * ((input) / max-pxcor)^(7)
let newvalue precision (value * max-pxcor ) 5
to-report taylor-approximation [input]
let value constant + x1-coefficient * ((input) / max-pxcor) + x2-coefficient * ((input) / max-pxcor)^ 2 / factorial 2 + x3-coefficient * ((input) / max-pxcor)^ 3 / factorial 3 + x4-coefficient * ((input) / max-pxcor)^ 4 / factorial 4 + x5-coefficient * ((input) / max-pxcor)^ 5 / factorial 5 + x6-coefficient * ((input) / max-pxcor)^ 6 / factorial 6 + x7-coefficient * ((input) / max-pxcor)^ 7 / factorial 7
let newvalue precision (value * max-pxcor ) 5
if xcord = max-pxcor [ stop ]
let y taylor-approximation xcord
ask patches with [ pxcor = xcord and pycor = round y] [sprout-points2 1 [ setup-appearance ]]
if xcord = max-pxcor - 1[ stop ]
let y taylor-approximation xcord
if y < max-pycor and y > min-pycor [
let prev one-of turtles with [ xcor = xcord and ycor = round y]
let nexty taylor-approximation (xcord + 1)
if nexty < max-pycor and y > min-pycor [
let next one-of turtles with [ xcor = (xcord + 1) and ycor = round nexty]
if y > min-pycor and y < max-pxcor and nexty > min-pycor and nexty < max-pycor [
ask prev [create-link-with next ask my-links [set color red]]
to-report factorial [input]
if input = 1 [ report 1 ]
report input * factorial (input - 1)